Ext.ns('SupplyView');

SupplyView = Ext.extend(Ext.Panel, {
	topbar : null,
	searchPanel : null,
	gridPanel : null,
	store : null,
	constructor : function(_cfg) {
		Ext.applyIf(this, _cfg);
		this.initUIComponents();
		SupplyView.superclass.constructor.call(this, {
					id : 'SupplyView',
					title : '资产基本资料补充录入',
					region : 'center',
					layout : 'border',
					items : [this.searchPanel, this.gridPanel]
				});
	},
	onSearch:function(obj){
			var searchPanel = Ext.getCmp('SupplyViewFormPanel');
			var gridPanel = Ext.getCmp('SupplyGrid');
			if (searchPanel.getForm().isValid()) {
				$search({
					searchPanel :searchPanel,
					gridPanel : gridPanel
				});
			}
	},
	initUIComponents : function() {
		this.searchPanel = new Ext.FormPanel({
			id : 'SupplyViewFormPanel',
			height : 100,
			region : 'north',
			frame : false,
			border : false,
			padding : '10',
			layout : 'column',
			title : '查询条件',
			labelWidth : 60,
			layoutConfig : {
				padding : '5',
				align : 'middle'
			},
			defaults : {
				border : false,
				columnWidth : 0.33,
				layout : 'form',
				width : 160,
				padding : '0 0 0 10'
			},
			items : [ {
				items : [ {
					fieldLabel : '资产编号',
					xtype : 'textfield',
					name : 'Q_assetNo_S_LK'
				}, {
					fieldLabel : '资产描述',
					xtype : 'textfield',
					name : 'Q_assetDesc_S_LK'
				} ]
			}, {
				items : [ {
					fieldLabel : '房屋编号',
					xtype : 'textfield',
					name : 'Q_houseId_S_LK'
				}, new Ext.Button({
					iconCls : 'search',
					text : '查询',
					scope : this,
					handler : this.onSearch.createCallback(this)
				}) ]
			} ]
		});// end of the searchPanel

		this.store = new Ext.data.Store({
			proxy : new Ext.data.HttpProxy({
				url : __ctxPath + '/pdaweb/listSupply.do'
			}),
			reader : new Ext.data.JsonReader({
						root : 'result',
						totalProperty : 'totalCounts',
						fields : ['assetNo','houseId','locationId', 
						          'assetDesc','barCode','parent','classStructureId']
					}),
			remoteSort : true
		});

		this.store.load({
			params : {
				start : 0,
				limit : 25
			}
		});
		 
		var cm = new Ext.grid.ColumnModel({
			defaults : {
				sortable : true,
				menuDisabled : false
			},
			columns : [new Ext.grid.RowNumberer(), {
				hidden:true,
				dataIndex : 'parent'
			},{
				header : '资产编号',
				width:120,
				dataIndex : 'assetNo'
			}, {
				header : '房屋编号',
				width:140,
				dataIndex : 'houseId'
			}, {
				header : '位置信息',
				dataIndex : 'locationId',
				width:100
			}, {
				header : '资产描述',
				width:160,
				dataIndex : 'assetDesc'
			},{
				hidden : true,
				dataIndex : 'barCode'
			},{
				hidden : true,
				dataIndex : 'parent'
			},{
				hidden : true,
				dataIndex : 'classStructureId'
			},{
				header : '操作',
				dataIndex : 'amId',
				sortable : false,
				renderer : function(value, metadata, record, rowIndex,
						colIndex) {
					return '&nbsp;<button title="补充资料" value=" " class="btn-edit" '
							+ 'onclick="new SupplyForm({\'rec\':\''+
							Ext.urlEncode(record.data)
							+'\'}).show();">&nbsp</button>';
				}
			}]
		});

		this.gridPanel = new Ext.grid.GridPanel({
					id : 'SupplyGrid',
					region : 'center',
					store : this.store,
					loadMask : true,
					autoHeight : true,
					cm : cm,
					viewConfig : {
						forceFit : true,
						enableRowBody : false
					},
					bbar : new Ext.PagingToolbar({
								pageSize : 25,
								store : this.store,
								displayInfo : true,
								displayMsg : '当前显示从{0}至{1}， 共{2}条记录',
								emptyMsg : "当前没有记录"
							})
				});

	}
});
